//
//  testScoreFor.c
//  dominion
//
//  Created by Doug Mason on 3/8/14.
//  Copyright (c) 2014 Doug Mason. All rights reserved.
//

#include <stdio.h>
#include "testScoreFor.h"

int fullDeckCount(int player, int card, struct gameState *state) {
    int i;
    int count = 0;
    
    for (i = 0; i < state->deckCount[player]; i++)
    {
        if (state->deck[player][i] == card) count++;
    }
    
    for (i = 0; i < state->handCount[player]; i++)
    {
        if (state->hand[player][i] == card) count++;
    }
    
    for (i = 0; i < state->discardCount[player]; i++)
    {
        if (state->discard[player][i] == card) count++;
    }
    
    return count;
}

int testScoreFor(int player,struct gameState* state){
    int i;
    int score = 0;
    int compare_score = scoreFor(player, state);
    for (i = 0; i < state->handCount[player]; i++) {
        if(state->hand[player][i]==curse){
            score -=1;
        }
        else if(state->hand[player][i]==estate){
            score+=1;
        }
        else if(state->hand[player][i]==duchy){
            score+=3;
        }
        else if(state->hand[player][i]==province){
            score+=6;
        }
        else if(state->hand[player][i]==great_hall){
            score+=1;
        }
        else if(state->hand[player][i]==gardens){
            score+=(fullDeckCount(player,0,state)/10);
        }
    }
    
    
    for(i = 0; i < state->discardCount[player];i++){
        if(state->discard[player][i]==curse){
            score -=1;
        }
        else if(state->discard[player][i]==estate){
            score+=1;
        }
        else if(state->discard[player][i]==duchy){
            score+=3;
        }
        else if(state->discard[player][i]==province){
            score+=6;
        }
        else if(state->discard[player][i]==great_hall){
            score+=1;
        }
        else if(state->discard[player][i]==gardens){
            score+=(fullDeckCount(player,0,state)/10);
        }
    }
    
    for (i = 0; i < state->deckCount[player]; i++) {
        if(state->deck[player][i]==curse){
            score -=1;
        }
        else if(state->deck[player][i]==estate){
            score+=1;
        }
        else if(state->deck[player][i]==duchy){
            score+=3;
        }
        else if(state->deck[player][i]==province){
            score+=6;
        }
        else if(state->deck[player][i]==great_hall){
            score+=1;
        }
        else if(state->deck[player][i]==gardens){
            score+=(fullDeckCount(player,0,state)/10);
        }
    }
    if(score!=compare_score){
        printf("Failed to compute score for player correctly\n");
        return -1;
    }
    else{
        printf("All tests for scoreFor passed.\n");
        return score;
    }
}